import pymongo

client = pymongo.MongoClient(host='localhost', port=27017)
# 选择数据库
db = client.test
# 选择集合
stu = db.stu

# 添加数据
res = stu.insert_one({'name':'张三', 'age':18})
# 获取搜入数据的id
s1_id = res.inserted_id
print(s1_id, type(s1_id))
print('添加数据成功！')

# 查询数据
# 藜取一条数据
s2 = stu.find_one()
print(s2)
# 遍历获取多条数据
for cur in stu.find():
    print(cur)